package gbench.appdemo.medicine.chemistry.solution;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

import gbench.common.matlib.rdd.BasePair;
import gbench.common.matlib.rdd.PVec;
import static gbench.common.tree.LittleTree.*;

/**
 * 
 * @author gbench
 *
 */
public class Solution extends BasePair<Solvent, List<Solute>> {

    /**
     * 
     * @param entry
     */
    public Solution(Solvent solvent, List<Solute> solutes) {
        super(solvent, solutes);
    }

    /**
     * 
     * @return
     */
    public PVec<String, Double> solutes() {
        return this._2.stream().map(e -> BasePair.bp(e.getName(), e.concentration())).collect(PVec.pvec2clc());
    }

    /**
     * 
     * @param Solutes
     * @return
     */
    public static Function<Solvent, Solution> BUILDER(final Solute... Solutes) {
        return solvent -> {
            return new Solution(solvent, Arrays.asList(Solutes));
        };
    }
    
    /**
     * 
     * @param Solutes
     * @return
     */
    public static Function<Solvent, Solution> BUILDER(final String... solutes) {
        return solvent -> {
            return new Solution(solvent, Arrays.stream(solutes).map(e->Solute.of(e)).collect(Collectors.toList()));
        };
    }
    
    /**
     * 
     * @param Solutes
     * @return
     */
    public static Solution OF(final Solute... Solutes) {
        return Solution.BUILDER(Solutes).apply(Solvent.WATER);
    }

    /**
     * 
     * @param Solutes
     * @return
     */
    public static Function<Solvent, Solution> BUILDER(Iterable<Solute> Solutes) {
        return solvent -> {
            return new Solution(solvent, iterable2list(Solutes));
        };
    }

}
